package com.atguigu.educms.service.impl;

import com.atguigu.common.cron.bean.FrontPageBean;
import com.atguigu.common.cron.vo.QuestionQueryVo;
import com.atguigu.educms.entity.QaQuestion;
import com.atguigu.educms.mapper.QaQuestionMapper;
import com.atguigu.educms.service.QaQuestionService;
import com.atguigu.educms.util.PageFrontUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 问答-帖子表 服务实现类
 * </p>
 *
 * @author Panghl
 * @since 2021-03-14
 */
@Service
public class QaQuestionServiceImpl extends ServiceImpl<QaQuestionMapper, QaQuestion> implements QaQuestionService {

    @Override
    public FrontPageBean getQuestionList(Integer pageNo, Integer pageSize, QuestionQueryVo questionQueryVo) {
        Page<QaQuestion> pageParam = new Page<>(pageNo,pageSize);
        QueryWrapper<QaQuestion> qw = new QueryWrapper<>();
        if (!StringUtils.isEmpty(questionQueryVo)){
            switch (questionQueryVo.getQt()){
                case "2":
                    qw.orderByDesc("qa_view");
                    break;
                case "3":
                    qw.eq("qa_comments",0);
                default:
                    qw.orderByDesc("gmt_create");
                    break;
            }
        }else {
            qw.orderByDesc("gmt_create");
        }
        baseMapper.selectPage(pageParam,qw);
        return PageFrontUtils.copyPropertiesFrontPage(pageParam);
    }

}
